import Dialog from '@vant/weapp/dialog/dialog';

Page({
    data: {
        navigationBar: 0,
        dataSite: {},
        startSiteSelectInfo: {},
        endSiteSelectInfo: {},
        priceInfo: {},
        typeList: [
            {
                name: '成人',
                price: '59.9',
                seatState: 0,
                passengerList: [
                    {
                        name: '朱广浩',
                        phone: '13539787747',
                        idCard: '441322199004205219',
                    },
                    {
                        name: '陈嘉盈',
                        phone: '13539787747',
                        idCard: '441322199004205219',
                    },
                    {
                        name: '张三',
                        phone: '13539787747',
                        idCard: '441322199004205219',
                    },
                ],
            },
            {
                name: '优惠',
                price: '45',
                seatValue: 0,
                passengerList: [
                    {
                        name: '朱广浩',
                        phone: '13539787747',
                        idCard: '441322199004205219',
                    },
                ]
            },
            {
                name: '儿童',
                price: '30',
                seatValue: 0,
                passengerList: []
            },
        ],
        passengerList: [
            {
                id: "0",
                name: '朱广浩',
                phone: '13539787747',
                idCard: '441322199004205219',
            },
            {
                id: "1",
                name: '陈嘉盈',
                phone: '13539787747',
                idCard: '441322199004205219',
            },
            {
                id: "2",
                name: '张三',
                phone: '13539787747',
                idCard: '441322199004205219',
            },
            {
                id: "3",
                name: '张四',
                phone: '13539787747',
                idCard: '441322199004205219',
            },
            {
                id: "4",
                name: '张五',
                phone: '13539787747',
                idCard: '441322199004205219',
            },
            {
                id: "5",
                name: '张六',
                phone: '13539787747',
                idCard: '441322199004205219',
            },
            {
                id: "5",
                name: '张六',
                phone: '13539787747',
                idCard: '441322199004205219',
            },
            {
                id: "5",
                name: '张六',
                phone: '13539787747',
                idCard: '441322199004205219',
            },
            {
                id: "5",
                name: '张六',
                phone: '13539787747',
                idCard: '441322199004205219',
            },
            {
                id: "5",
                name: '张六',
                phone: '13539787747',
                idCard: '441322199004205219',
            },
        ],
        priceSelect: "0",
        showPopup: false,
    },
    onLoad: function (options) {
        const eventChannel = this.getOpenerEventChannel();
        eventChannel.on('acceptDataFromOpenerPage', (data) => {
            console.log("data", data);
            const {dataSite, startSiteSelectInfo, endSiteSelectInfo, priceInfo} = data;
            const systemInfo = wx.getSystemInfoSync();
            const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
            this.setData({
                navigationBar: (menuButtonInfo.top - (systemInfo?.statusBarHeight || 0)) * 2 + menuButtonInfo.height,
                dataSite: dataSite,
                startSiteSelectInfo: startSiteSelectInfo,
                endSiteSelectInfo: endSiteSelectInfo,
                priceInfo: priceInfo,
            })
        })

    },

    addPassenger: function (e) {
        this.setData({
            showPopup: true
        });
        // const index = e.currentTarget.dataset.index;
        // const typeList = [...this.data.typeList];
        // typeList[index].passengerList.push({
        //     name: '王德发',
        //     phone: '13539787747',
        //     idCard: '441322199004205219',
        // });
        // this.setData({
        //     typeList: typeList
        // });
    },
    deletePassenger: function (e) {
        const typeIndex = e.currentTarget.dataset.typeIndex;
        const passengerIndex = e.currentTarget.dataset.passengerIndex;
        console.log(typeIndex, passengerIndex);
        const typeList = [...this.data.typeList];
        typeList[typeIndex].passengerList.splice(passengerIndex, 1);
        this.setData({
            typeList: typeList
        });
    },

    onSheetClose() {
        this.setData({
            showPopup: false
        });
    },

    toTicketAdd: function () {
        this.onSheetClose();
        wx.navigateTo({
            url: `/pages/sitebus/passenger/passenger`,
            success: function (res) {
            }
        });
    },


    toTicketEdit: function () {
        this.onSheetClose();
        wx.navigateTo({
            url: `/pages/sitebus/passenger/passenger`,
            success: function (res) {
            }
        });
    },
    deleteSheetPassenger: function (e) {
        Dialog.confirm({
            message: '确定删除此乘车联系人信息？',
        })
            .then(() => {
                // on confirm
            })
            .catch(() => {
                // on cancel
            });
    },

    onClickButton: function (e) {

    }

});